/**
 * 房屋出售详情对话框
 */
var HouseSellInfo = {
    id: "housesellinfoTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
HouseSellInfo.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id',align: 'center', valign: 'middle'},
        {title: '标题', field: 'house_title', align: 'center', valign: 'middle', sortable: true},
        {title: '类型', field: 'source_name', align: 'center', valign: 'middle', sortable: true},
        {title: '委托人', field: 'owner_name', align: 'center', valign: 'middle', sortable: true},
        {title: '是否置顶', field: 'top', align: 'center', valign: 'middle', sortable: true},
        {title: '浏览次数', field: 'visit_num', align: 'center', valign: 'middle', sortable: true},
        {title: '被举报次数', field: 'report_num', align: 'center', valign: 'middle', sortable: true},
        {title: '是否已成交', field: 'deal', align: 'center', valign: 'middle', sortable: true},
        {title: '发布日期', field: 'publish_date', align: 'center', valign: 'middle', sortable: true},
        {title: '审核人', field: 'auditor', align: 'center', valign: 'middle', sortable: true}];
    return columns;
};

/**
 * 检查是否选中
 */
HouseSellInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        HouseSellInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击详情按钮时
 * @param userId 管理员id
 */
HouseSellInfo.openHouseInfo = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '房源出售详情',
            area: ['900px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/housesellinfo/view/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 编辑
 */
HouseSellInfo.openHouseVisitInfo = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '编辑浏览次数',
            area: ['500px', '300px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/visit/sell_visit_update/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 点击详情按钮时
 * @param userId 管理员id
 */
HouseSellInfo.openHouseReport = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '被举报详情',
            area: ['900px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/housesellinfo/report/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除房源
 */
HouseSellInfo.deleteHouse = function () {
    if (this.check()) {

        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/housesellinfo/delete", function () {
                Feng.success("删除成功!");
                HouseSellInfo.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id",HouseSellInfo.seItem.id);
            ajax.start();
        };

        Feng.confirm("是否刪除该房源?", operation);
    }
};

HouseSellInfo.resetSearch = function () {
    $("#title").val("");
    $("#beginTime").val("");
    $("#endTime").val("");

    HouseSellInfo.search();
}

HouseSellInfo.search = function () {
    var queryData = {};

    queryData['title'] = $("#title").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

   HouseSellInfo.table.refresh({query: queryData});
}

$(function () {
    var defaultColunms = HouseSellInfo.initColumn();
    var table = new BSTable("housesellinfoTable", "/housesellinfo/list", defaultColunms);
    table.setPaginationType("client");
    HouseSellInfo.table = table.init();
});
